<?php

namespace api\modules\goods\controllers;

use Yii;
use api\modules\goods\models\Goods;
use api\modules\goods\models\search\GoodsSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use api\token\tokenCheck;

/**
 * GoodsController implements the CRUD actions for Goods model.
 */
class GoodsController extends Controller
{
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],
        ];
    }

    /**
     * @return string
     */
    public function actionIndex()
    {
        $post = Yii::$app->request->post();
        $checkData = isset($post['checkData'])?$post['checkData']:'';
        if($checkData){
            $token = new tokenCheck();
            $goods_id = $post['data']['goods_id'];
            if($token->check($checkData['userid'],$checkData['access_token'])){
                $goodARR = Goods::find()->where(['goods_id'=>$goods_id])->asArray()->one();
                $message = ['code'=>200,'message'=>'登录成功','data'=>$goodARR];
                return json_encode($message);
            }
        } else {
            $message = ['code'=>500,'message'=>'token验证失败'];
            return json_encode($message);
        }
    }
}
